package com.ellwood.copyright.common.core.enums;

import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * @ProjectName: ell-copyright-pro
 * @PackageName: com.ellwood.copyright.common.core.enums
 * @ClassName: EnumConverter
 * @Description: // 类型转换的枚举
 * @Author: Ellwood
 * @CreateDate: 2024/12/23 - 11:56
 * @Version: V1.0.0
 */

@Getter
public enum EnumConverter {

    // 性别转换
    GENDER,
    // 状态转换
    STATUS;

    // 存储每个类型对应的映射关系
    private Map<Integer,String> codeToStringMap =new HashMap<>();
    private Map<String,Integer> stringToCodeMap =new HashMap<>();

    // 构造方法：根据枚举类型填充转换映射
    EnumConverter(){
        switch (this){
            case GENDER:
                codeToStringMap.put(0, "男");
                codeToStringMap.put(1, "女");
                codeToStringMap.put(2, "未知");

                stringToCodeMap.put("男", 0);
                stringToCodeMap.put("女", 1);
                stringToCodeMap.put("未知", 2);
                break;
            case STATUS:
                codeToStringMap.put(0, "正常");
                codeToStringMap.put(1, "锁定");

                stringToCodeMap.put("正常", 0);
                stringToCodeMap.put("锁定", 1);
                break;
        }
    }

    /**
     * 根据 code 获取对应的 String 值
     * @param code Integer
     * @return 返回value
     */
    public String convert(Integer code){
        return codeToStringMap.getOrDefault(code,"未知");
    }

    /**
     * 根据字符串获取对应的 Integer 值
     * @param value String
     * @return 返回value
     */
    public Integer convert(String value){
        return stringToCodeMap.getOrDefault(value, -1); // 如果找不到映射，返回-1
    }

}
